//
//  XCollectionViewController.m
//  Bees
//
//  Created by NowYouCanSee on 2018/12/25.
//  Copyright © 2018 xiaohan. All rights reserved.
//

#import "XCollectionViewController.h"
#import "HMScanner.h"
@interface XCollectionViewController ()
@property (nonatomic,copy) NSString*account;
@end

@implementation XCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI{
    self.account = CURRENT_WALLET.wallet_name;
    self.title = XLocalized(@"收款");
    self.navBarTintColor = UIColor.whiteColor;
    self.customNavigationBar.backgroundColor = [UIColor blackColor];
    self.leftBackImg = @"white_back";
    self.StatusBarStyle = UIStatusBarStyleLightContent;
    self.view.backgroundColor = [UIColor blackColor];
    UIView *contentView = [UIView new];
    contentView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kNormalSpace);
        make.right.mas_equalTo(-kNormalSpace);
        make.top.equalTo(self.customNavigationBar.mas_bottom).offset(AdaptedHeight(25));
        make.height.mas_equalTo(AdaptedWidth(400));
    }];
    contentView.layer.cornerRadius = AdaptedWidth(13);
    [self addNavigationItemWithImageNames:@[@"share"] isLeft:NO target:self action:@selector(shareClick) tags:nil];
    
    UILabel *titleLab = [UILabel new];
    titleLab.textColor = UIColorHex(333333);
    titleLab.text = XLocalized(@"扫描二维码向我付款");
    titleLab.font = kBoldFont(16);
    [contentView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(AdaptedWidth(45));
        make.centerX.mas_equalTo(0);
    }];
    
    UIImageView*codeImageView = [UIImageView new];
    [contentView addSubview:codeImageView];
    [codeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLab.mas_bottom).offset(AdaptedWidth(35));
        make.left.mas_equalTo(AdaptedWidth(68));
        make.right.mas_equalTo(AdaptedWidth(-68));
        make.height.equalTo(codeImageView.mas_width);
    }];
    [HMScanner qrImageWithString:self.account avatar:nil completion:^(UIImage *image) {
        codeImageView.image = image;
    }];
    
    UILabel *subLab = [UILabel new];
    subLab.textColor = UIColorHex(#B5B5B5);
    subLab.font = kBoldFont(15);
    [contentView addSubview:subLab];
    [subLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(codeImageView.mas_bottom).offset(AdaptedWidth(20));
        make.centerX.mas_equalTo(0);
    }];
    subLab.text = XLocalized(@"EOS 账号");
    
    UILabel*nameLab = [UILabel new];
    nameLab.textColor = UIColorHex(B5B5B5);
    nameLab.font = kBoldFont(15);
    [contentView addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(subLab.mas_bottom).offset(AdaptedWidth(10));
        make.centerX.mas_equalTo(0);
    }];
    
    nameLab.text = self.account;
    
    XThemeFlatButton *bottomBtn = [XThemeFlatButton new];
    [bottomBtn setTitle:XLocalized(@"复制账号名称") forState:UIControlStateNormal];
    [self.view addSubview:bottomBtn];
    [bottomBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(contentView.mas_bottom).offset(AdaptedWidth(70));
        make.left.mas_equalTo(kNormalSpace);
        make.right.mas_equalTo(-kNormalSpace);
        make.height.mas_equalTo(AdaptedWidth(40));
    }];
    kWeakSelf(self);
    [bottomBtn addTapBlock:^(UIButton * _Nonnull btn) {
        if (weakself.account.length) {
            UIPasteboard *pab = [UIPasteboard generalPasteboard];
            [pab setString:weakself.account];
            if (pab == nil) {
                [weakself.view makeToast:XLocalized(@"复制失败!")];
            }else
            {
                [weakself.view makeToast:XLocalized(@"复制成功!")];
            }
        }
    }];
}

- (void)shareClick{
    [self.view makeToast:@"功能暂未开放"];
}
@end
